package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.system.domain.HupRegion;
import com.ruoyi.system.mapper.HupRegionMapper;
import com.ruoyi.system.service.IHupRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class HupRegionServiceImpl implements IHupRegionService {

    @Resource
    private HupRegionMapper hupRegionMapper;

    @Override
    public HupRegion getRegionById(Integer id) {
        return hupRegionMapper.selectById(id);
    }

    @Override
    public List<HupRegion> getProvinces() {
        QueryWrapper<HupRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("level", 1);
        return hupRegionMapper.selectList(wrapper);
    }

    @Override
    public List<HupRegion> getChildrenRegions(Integer pid) {
        QueryWrapper<HupRegion> wrapper = new QueryWrapper<>();
        wrapper.eq("pid", pid);
        return hupRegionMapper.selectList(wrapper);
    }

    @Override
    public List<HupRegion> searchRegions(String keyword) {
        return hupRegionMapper.selectByName(keyword);
    }

    @Override
    public HupRegion getRegionByLngLat(String lng, String lat) {
        return hupRegionMapper.selectByLngLat(lng, lat);
    }
}
